<?php
/**
 * 盘点方案
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/4/18
 * Time: 15:37
 */
namespace App\Http\Controllers\WarehouseManage;
use App\Http\Controllers\ApiController;
use App\Services\Warehouse\StockCountSchemeService;
use Illuminate\Http\Request;

class StockCountSchemeController extends ApiController {

    protected $StockCountSchemeService;
    public function __construct(StockCountSchemeService $stockCountSchemeService)
    {
        $this->StockCountSchemeService=$stockCountSchemeService;
    }

    /***
     * 创建盘点方案
     * 参数说明
     * pdata={"wid":8,"goods_sn":"s123456","note":"测试"}
     * @param Request $request
    @author echa
     * @return mixed
     */
    public function CreateStockCountScheme(Request $request){
        $pdata=$request->pdata;
        if(empty($pdata)){
            return $this->failed('非法请求');
        }
        $pdata=json_decode($pdata,true);
        if(empty($pdata)){
            return $this->failed('参数错误');
        }
        $data=[
            'wid'=>$pdata['wid'],
            'goods_sn'=>$pdata['goods_sn'],
            'note'=>$pdata['note']
        ];
        try{
            $return=$this->StockCountSchemeService->CreateStockCountScheme($data);
            if($return){
                return $this->success($return);
            }else{
                return $this->failed('操作失败');
            }
        }catch (\Exception $exception){
            return $this->failed($exception->getMessage());
        }
    }

    /***
     * 审核盘点方案
     * @param Request $request
    @author echa
     * @return mixed
     */
    public function AuditStockCountScheme(Request $request){
        $Number=$request->number;
        if(empty($Number)){
            return $this->failed('非法操作');
        }
        try{
            $return=$this->StockCountSchemeService->AuditStockCountScheme([$Number]);
            if($return){
                return $this->success($return);
            }else{
                return $this->failed('操作失败');
            }
        }catch (\Exception $exception){
            return $this->failed($exception->getMessage());
        }
    }

    /***
     * 盘点方案提交并审核并查看对应物料盘点作业单明细
     * 参数说明
     * number  盘点方案编号
     * @param Request $request
    @author echa
     * @return mixed
     */
    public function SubmitAndAuditStockCountSchemeAndIO(Request $request){
        $Number=$request->number;
        if(empty($Number)){
            return $this->failed('非法操作');
        }
        try{
            $return=$this->StockCountSchemeService->SubmitAndAuditStockCountSchemeAndIO($Number);
            if($return){
                return $this->success($return);
            }else{
                return $this->failed('操作失败');
            }
        }catch (\Exception $exception){
            return $this->failed($exception->getMessage());
        }
    }
}